package top.ajunnihao.core.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.ajunnihao.core.web.interceptor.AdminLoginInterceptor;
import top.ajunnihao.core.web.interceptor.OrderInterceptor;

/**
 * <p>
 * Web Mvc 全局配置
 * </p>
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private OrderInterceptor orderInterceptor;
    @Autowired
    private AdminLoginInterceptor adminLoginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 未登录不可进入订单中心
        registry.addInterceptor(orderInterceptor)
                .addPathPatterns("/order/list");
        // 未登录不可进入管理员界面
        registry.addInterceptor(adminLoginInterceptor)
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin/login", "/admin/login.do", "/asserts/**", "/css/**", "/img/**", "/js/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 文件上传路径映射到本地文件
        registry.addResourceHandler("/upload/**").addResourceLocations("file:/D:/travelFile/");
    }

}
